<template>
  <div>
    <el-table border
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column> <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column> <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      </el-table>

    <!--layout布局-->
    <el-pagination
      background
      align="right"
      layout="prev, pager, next"
      :total="totals"
      :page-size="pageSize"
      :current-page="currentPage"
      @current-change="gotoPage">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      pageSize:5,
      currentPage:1,
      totals:0,
      tableData: []
    }
  },
  methods:{
    gotoPage(cuu){
      //cuu 就是当前点击的页码
      this.currentPage = cuu
      //调用接口
      this.findPage()
    },
    //请求后端接口，获取列表数据
    findPage(){
      // 发送axios请求，后端 获取接口(记录报错：少了"/user/list"少了第一个/)
      this.$http.post("/user/list",{"currentPage":this.currentPage,"pageSize":this.pageSize})
        .then(result=>{
        // 回调函数，就是请求后端成功了
        this.tableData = result.data.rows
        this.totals = result.data.totals
      })
      .catch(result=>{
          alert("网络不行")
      })
    }
  },
  mounted() {
    //页面第一次初始化的时候，去请求接口
    this.findPage();
  }
}
</script>
